import 'package:dio/dio.dart';
import 'package:flutter/material.dart';
import 'package:proj_shop/constant/constant.dart';
import 'package:proj_shop/http/weibo/http_weibo.dart';
import 'package:proj_shop/http/weibo/weibo_service_url.dart';
import 'package:proj_shop/roots/weibo/routers/weibo_routes.dart';
import 'package:proj_shop/roots/weibo/widgets/account_editText.dart';
import 'package:proj_shop/roots/weibo/widgets/textField_pwd.dart';

class WeiboLoginPage extends StatefulWidget {
  @override
  _WeiboLoginPageState createState() => _WeiboLoginPageState();
}

String _inputAccount = "";
String _inputPwd = "";

class _WeiboLoginPageState extends State<WeiboLoginPage> {
  @override
  Widget build(BuildContext context) {
    return Scaffold(
      body: ListView(
        children: [
          buildTile(),
          buildInputPass(),
          Container(
            margin: EdgeInsets.only(top: 10, left: 20, right: 20),
            child: AccountEditText(
              contentStrCallBack: (str) {
                _inputAccount = str;
                setState(() {});
              },
            ),
          ),
          Container(
            margin: EdgeInsets.only(top: 10, left: 20, right: 20),
            child: TextFieldPwd(
              contentStrCallBack: (content) {
                _inputPwd = content;
                setState(() {});
              },
            ),
          ),
          buildLoginBtn(),
          buildRegistForget(),
          buildOtherLoginWay(),
          buildRichText(),
        ],
      ),
    );
  }

  Container buildInputPass() {
    return Container(
      margin: const EdgeInsets.only(
        left: 20.0,
        top: 30.0,
        bottom: 20,
        right: 20.0,
      ),
      child: Text(
        "请输入账号密码",
        style: TextStyle(fontSize: 24.0, color: Colors.black),
      ),
    );
  }

  Widget buildTile() {
    return Row(
      mainAxisAlignment: MainAxisAlignment.spaceBetween, //子组件的排列方式为主轴两端对齐
      children: <Widget>[
        new InkWell(
          child: new Padding(
              padding: const EdgeInsets.all(12.0),
              child: Image.asset(
                Constant.ASSETS_IMG + 'icon_close.png',
                width: 20.0,
                height: 20.0,
              )),
          onTap: () {
            // Navigator.pop(context);
          },
        ),
        new InkWell(
          child: new Padding(
              padding: const EdgeInsets.all(12.0),
              child: new Text(
                "帮助",
                style: new TextStyle(fontSize: 16.0, color: Color(0xff6B91BB)),
              )),
          onTap: () {},
        ),
      ],
    );
  }

  Widget buildLoginBtn() {
    return Container(
      margin: const EdgeInsets.only(left: 20.0, right: 20.0, top: 60.0),
      child: RaisedButton(
        color: Color(0xffFF8200),
        textColor: Colors.white,
        disabledTextColor: Colors.white,
        disabledColor: Color(0xffFFD8AF),
        elevation: 0,
        disabledElevation: 0,
        highlightElevation: 0,
        onPressed: () {
          // WeiboRoutes().pushNamedAndRemoveAllStack(WeiboRoutes.find_hot_serch);
          // return;
          // if (_inputAccount.isEmpty || _inputPwd.isEmpty) {
          //   print("input all please!");
          //   return;
          // }
          WeiboRoutes().pushNamedAndRemoveAllStack(WeiboRoutes.index);
          // FormData params = FormData.fromMap({
          //   'username': _inputAccount,
          //   'password': _inputPwd,
          // });
          // HttpWeibo().post(
          //   WeiboServiceUrl.login,
          //   params,
          //   (data) {
          //     // UserUtil.saveUserInfo(data['data']);
          //     // ToastUtil.show('登录成功!');
          //     // Navigator.pop(context);
          //     // Routes.navigateTo(context, Routes.indexPage);
          //   },
          //   (error) {},
          // );
        },
        child: Padding(
          padding: EdgeInsets.fromLTRB(0.0, 10.0, 0.0, 10.0),
          child: Text(
            "登  录",
            style: TextStyle(fontSize: 16.0),
          ),
        ),
      ),
    );
  }

  //注册,忘记密码
  Widget buildRegistForget() {
    return Row(
      mainAxisAlignment: MainAxisAlignment.spaceBetween, //子组件的排列方式为主轴两端对齐
      children: <Widget>[
        new InkWell(
          child: new Padding(
              padding: const EdgeInsets.only(left: 20.0, top: 3),
              child: new Text(
                "注册",
                style: new TextStyle(fontSize: 13.0, color: Color(0xff6B91BB)),
              )),
          onTap: () {},
        ),
        new InkWell(
          child: new Padding(
              padding: const EdgeInsets.only(right: 20.0, top: 3),
              child: new Text(
                "忘记密码",
                style: new TextStyle(fontSize: 13.0, color: Color(0xff6B91BB)),
              )),
          onTap: () {},
        ),
      ],
    );
  }

  //其他登陆方式
  Widget buildOtherLoginWay() {
    return Column(
      children: <Widget>[
        Row(
          mainAxisAlignment: MainAxisAlignment.spaceAround,
          children: <Widget>[
            Expanded(
              child: Container(
                margin: EdgeInsets.only(left: 20),
                color: Color(0xffEAEAEA),
                height: 1,
              ),
              flex: 1,
            ),
            Expanded(
              child: Container(
                child: Center(
                  child: Text(
                    '其他登陆方式',
                    style: TextStyle(fontSize: 12, color: Color(0xff999999)),
                  ),
                ),
              ),
              flex: 1,
            ),
            Expanded(
              child: Container(
                margin: EdgeInsets.only(right: 20),
                color: Color(0xffEAEAEA),
                height: 1,
              ),
              flex: 1,
            ),
          ],
        ),
        Row(
          mainAxisAlignment: MainAxisAlignment.center,
          //crossAxisAlignment: CrossAxisAlignment.center,
          children: <Widget>[
            Container(
              margin: EdgeInsets.only(right: 20, top: 10),
              child: Column(
                children: <Widget>[
                  Image.asset(
                    Constant.ASSETS_IMG + 'login_weixin.png',
                    width: 40.0,
                    height: 40.0,
                  ),
                  Container(
                    margin: EdgeInsets.only(top: 5),
                    child: Text(
                      '微信',
                      style: TextStyle(fontSize: 12, color: Color(0xff999999)),
                    ),
                  )
                ],
              ),
            ),
            Container(
              margin: EdgeInsets.only(left: 20, top: 10),
              child: Column(
                children: <Widget>[
                  Image.asset(
                    Constant.ASSETS_IMG + 'login_qq.png',
                    width: 40.0,
                    height: 40.0,
                  ),
                  Container(
                    margin: EdgeInsets.only(top: 5),
                    child: Text(
                      'QQ',
                      style: TextStyle(fontSize: 12, color: Color(0xff999999)),
                    ),
                  )
                ],
              ),
            ),
          ],
        )
      ],
    );
  }

  Widget buildRichText() {
    return Container(
      margin: EdgeInsets.only(top: 30),
      child: Column(
        children: [
          RichText(
            text: TextSpan(
              text: "TextSpan",
              style: TextStyle(
                color: Colors.red,
              ),
            ),
          ),
        ],
      ),
    );
  }
}
